package com.test.langchain4j.config;

import com.test.langchain4j.constant.QdrantConstant;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.model.openai.OpenAiEmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.qdrant.QdrantEmbeddingStore;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 2025/8/4 08:42
 * @modifiedBy:
 * @version: 1.0
 */
@Configuration
public class LLMConfig {
  @Bean
  public EmbeddingModel embeddingModel() {
    return OpenAiEmbeddingModel.builder()
        .apiKey(System.getenv("qwen-api-key"))
        .modelName("text-embedding-v4")
        .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
        .build();
  }

  @Bean
  public QdrantClient qdrantClient() {
    QdrantGrpcClient.Builder grpcClientBuilder =
        QdrantGrpcClient.newBuilder("10.2.54.170", 6334, false);
    return new QdrantClient(grpcClientBuilder.build());
  }

  @Bean
  public EmbeddingStore<TextSegment> embeddingStore() {
    return QdrantEmbeddingStore.builder()
        .host("10.2.54.170")
        .port(6334)
        .collectionName(QdrantConstant.COLLECTION_NAME)
        .build();
  }
}
